package com.ibm.risk.irmp.base.auth.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ibm.risk.irmp.base.auth.entity.SystemUserBase;
import com.ibm.risk.irmp.common.auth.vo.LoginUser;
import com.ibm.risk.irmp.common.auth.vo.OrgInfoVo;
import com.ibm.risk.irmp.common.auth.vo.RoleVo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Delegate;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;


@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserDetailVo extends LoginUser {
    @Delegate
    @JsonIgnore
    private SystemUserBase user;

    private List<? extends RoleVo> roles = new ArrayList<>();
    private List<? extends OrgInfoVo> bizOrgs = new ArrayList<>();
    private List<? extends OrgInfoVo> mngOrgs = new ArrayList<>();

    public boolean isAccountNonExpired() {
        return !((user.getValidFrom() != null && user.getValidFrom().isAfter(LocalDate.now())) ||
                (user.getValidTo() != null && user.getValidTo().isBefore(LocalDate.now())));
    }

    public boolean isAccountNonLocked() {
        return getStatus() != LoginUser.Status.LOCKED;
    }

    public boolean isCredentialsNonExpired() {
        return false;
    }

    public boolean isEnabled() {
        return user.getStatus() == LoginUser.Status.ACTIVE;
    }
}
